#ifndef _ROT_H_
#define _ROT_H_

#include "stdafx.h"

class CComRunningObjectTableImpl	:	public IComRotMessage,
								public CUnknownImp
{
public:
	CComRunningObjectTableImpl(void);
	~CComRunningObjectTableImpl(void);

public:
	BEGIN_STDCOM_MAP
		STDCOM_INTERFACE_ENTRY_UNKNOWN_(IComRunningObjectTable)
		STDCOM_INTERFACE_ENTRY(IComRunningObjectTable)
		STDCOM_INTERFACE_ENTRY(IComRotMessage)
	END_STDCOM_MAP

public: 
	// IComRunningObjectTable:
	std_method(CreateInstance)(IBase* rot, REFCLSID clsid, IBase* punk, REFIID iid, void **ppv);
	std_method(Register)(REFCLSID clsid, LPCSTR progId, IBase *punk, UINT id);
	std_method(Revoke)(REFCLSID clsid);
	std_method(IsRunning)(REFCLSID clsid);
	std_method(GetObject)(REFCLSID clsid, REFIID iid, IBase **ppunk);
	std_method(RevokeAll)();
	std_method_(LPCSTR, ProgIDFromCLSID)(REFCLSID clsid);
	std_method_(CLSID, CLSIDFromProgID)(LPCSTR lpProgId);
	std_method_(ULONG, GetObjectCount)();

	// IComRotMessage:
	std_method(CreateMessage)(IBase** pMsg);
	std_method(SendMessage)(REFCLSID sn, REFCLSID tn, ULONG gp, UINT msg, IBase* pMsg);
	std_method(PostMessage)(REFCLSID sn, REFCLSID tn, ULONG gp, UINT msg, IBase* pMsg);
private:
	std_method(GetBaseObject)(REFCLSID clsid, REFIID iid, IBase **ppunk);
private:
	typedef struct tagRunningTableItem
	{
		string	progid;
		CLSID	cls;
		BasePtr m_ptr;
		UINT index;
	}RUNNINGTABLEITEM;

	typedef std::map<GUID, RUNNINGTABLEITEM, memless<CLSID> > OBJMAP;
	OBJMAP m_map;
	CAutoLock		m_lockSection;
};

#endif
